import os
import allure
import pytest
from selenium import webdriver

from config.config import BASE_DIR, CDIA_folder_path, organization_id
from api.wf_upload_api import WfUploadApi
from util.file_util import update_sys_biz_date
from util.insert_daily_result_util import insert_daily_calculation_result
from util.sftp_util import SFTPUtil
from util.upload_etl_data_util import batch_upload_files_with_wait


@pytest.fixture(scope="class")
def setup_wf_upload_api():
    wf_upload_api = WfUploadApi()
    yield wf_upload_api
    wf_upload_api.session.close()


@pytest.fixture(scope="class")
def setup_wf_calculation_happy_case():
    wf_upload_api = WfUploadApi()
    csv_file_path = f"{BASE_DIR}/data/calculation/happy_case/low_case/daily_calculation_result(202412)/audit.csv"
    twr_csv = f"{BASE_DIR}/data/calculation/happy_case/low_case/daily_calculation_result(202412)/daily_twr(202412).csv"
    agg_csv = f"{BASE_DIR}/data/calculation/happy_case/low_case/daily_calculation_result(202412)/daily_twr_aggregate(202412).csv"
    # insert_daily_calculation_result(csv_file_path, twr_csv, agg_csv)
    #　batch_upload_files_with_wait(os.path.join(BASE_DIR, "data", "calculation", "happy_case"))
    sftp_util = SFTPUtil()
    source_directory = os.path.join(BASE_DIR, "data", "calculation", "happy_case", "low_case", "20241231")
    sftp_util.upload_calculation_files(source_directory)
    sftp_util.delete_ack_files()
    sftp_util.delete_file(f"{CDIA_folder_path}/{organization_id}/work/ppa.lock")
    yield wf_upload_api
    wf_upload_api.session.close()
